<template>
  <div id="app-content">
    <SidebarMenu />
    <div class="main-content">
      <router-view />
    </div>
  </div>
</template>

<script setup>
import SidebarMenu from '@/components/SidebarMenu.vue';
import { get } from '@/utils/request';
import store from '@/store';

const getGuestToken = async () => {
  try {
    // 检查是否已有token且不是游客
    const user = store.state.SmartNeroUser;
    
    if (user?.token && !user?.isGuest) return;

    const response = await get('/guest');
    if (response.status !== 200) throw new Error(response.message);
    
    store.commit('setSmartNeroUser', {
      token: response.data.token,
      isGuest: true,
      expires: Date.now() + 86400000
    });
  } catch (error) {
    console.error('获取游客token失败:', error);
    store.commit('clearUser');
  }
};

getGuestToken();
</script>

<style>
#app{
  height: 100%;
}

body {
    margin: 0;
    font-size: 14px;
    font-family: v-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

#app-content {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: 68px;
  width: calc(100% - 68px);
  overflow: hidden;
}
</style>
